package com.heima.wemedia.controller.v1;

import com.heima.common.constants.WemediaConstants;
import com.heima.model.common.dtos.PageResponseResult;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dtos.WmMaterialDto;
import com.heima.model.wemedia.pojos.WmMaterial;
import com.heima.wemedia.service.WmMaterialService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@RestController
@RequestMapping("/api/v1/material")
public class WmMaterialController {

    @Autowired
    private WmMaterialService wmMaterialService;

    /**
     * 文件上传
     * @param multipartFile
     * @return
     */
    @PostMapping("/upload_picture")
    public ResponseResult upload_picture(MultipartFile multipartFile) {
       WmMaterial wmMaterial = wmMaterialService.uploadPicture(multipartFile);
        return ResponseResult.okResult(wmMaterial);
    }

    /**
     * 素材链表查询
     * @param wmMaterialDto
     * @return
     */
    @PostMapping("/list")
    public ResponseResult listWmMaterial(@RequestBody WmMaterialDto wmMaterialDto){

        return wmMaterialService.listWmMaterial(wmMaterialDto);
    }

    @GetMapping("/del_picture/{id}")
    public ResponseResult deleteWmMaterial(@PathVariable Integer id){
        return  wmMaterialService.deleteWmMaterialById(id);
    }

    /**
     * 收藏
     */
    @GetMapping("/collect/{id}")
    public ResponseResult collectWmMaterial(@PathVariable Integer id){
        return wmMaterialService.collectAndCollect(id, WemediaConstants.COLLECT_MATERIAL);
    }
    @GetMapping("/cancel_collect/{id}")
    public ResponseResult cancelCollectWmMaterial(@PathVariable Integer id){
        return wmMaterialService.collectAndCollect(id,WemediaConstants.CANCEL_COLLECT_MATERIAL);
    }

}
